package oj;

import java.util.LinkedList;
import java.util.Scanner;

public class Day24S {
    public static LinkedList<int[]> path;//存储最短路径
    public static LinkedList<int[]> list;//存储每一次路径
    public static int[][] mark;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()){
            list= new LinkedList<>();
            path= new LinkedList<>();
            int n=sc.nextInt();
            int m=sc.nextInt();
            int[][] a=new int[n][m];
            mark=new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j]=sc.nextInt();
                }
            }
            dfs(a,0,0);
            for (int i = 0; i < path.size(); i++) {
                System.out.println("(" + path.get(i)[0] +","+path.get(i)[1] +")");
            }
        }
    }

    private static void dfs(int[][] a, int x, int y) {
        if(x==a.length-1 && y==a[0].length-1){
            list.add(new int[]{x,y});
            if(list.size()< path.size() ||path.isEmpty()){
                path.clear();
                for (int i = 0; i < list.size(); i++) {
                    path.add(list.get(i));
                }
            }
            return;
        }
        //边界
        if(x<0 || y<0 || x>=a.length || y>=a[0].length || mark[x][y]==1 || a[x][y]==1){
            return;
        }
        //标记走过的路
        mark[x][y]=1;
        list.add(new int[]{x,y});
        dfs(a,x+1,y);
        dfs(a,x-1,y);
        dfs(a,x,y+1);
        dfs(a,x,y-1);
        //回溯  删除标记
        mark[x][y]=0;
        //删除路径
        list.remove(list.size()-1);
    }
}
